home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 051-075 / scopedisk70 / edible / edible.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  3KB  |  69 lines

  1. /***************************************************************************
  2.  *   This simple utility was written 20-Dec-87 by J. Christopher Redden    *
  3.  *    (214) 221-1619   248 Southwest Pkwy #1012 Lewisville, Tx. 75067      *
  4.  *                        GEnie address J.REDDEN                           *
  5.  *   I like to use ED, however, it is VERY frustrating to dload/capture    *
  6.  *   only to find that SOMEWHERE there is a binary that ED doesn't like.   *
  7.  * This will write from argv[1] to argv[2] while filtering unwanted chars  *
  8.  *   as it goes.  There is a third argument that will define the maximum   *
  9.  *  line length to be 1 to 255.  If argv[3] == 0 then all the line length  *
  10.  *  counter is ignored and lines can be as long as you like.  If there is  *
  11.  *            no argv[3] then a default value of 78 is set.                *
  12.  * Things to add: BACKSPACE handler; Window to show what and where is being*
  13.  * filtered out; TAB handler; stuff like that...  This will do for now.    *
  14.  **************************************************************************/
  15.  
  16. # include <stdio.h>
  17.  
  18. # define LFEED  0x0A
  19. # define RETURN 0x0D
  20. # define SPACE  0x20
  21. # define DELETE 0x7F
  22. # define SETLENGTH 78           /* default setting for maximum line length */
  23.  
  24. int maxlen = 0, len = 0;
  25.  
  26. main (argc, argv)
  27.  
  28. int argc;
  29. char *argv[];
  30. {
  31. int c;
  32.  
  33.   FILE *fp1, *fp2, *fopen();
  34.  
  35.    if (argc < 3) {   /* check to see there are at LEAST infile and outfile */
  36.       printf("USAGE: EDible <input file> <output file> [LineLength DEFAULT= 77, 0= disable]\n");
  37.       exit(1);   }
  38.    else if ((fp1 = fopen(argv[1],"r")) == NULL) {     /* does infile exist */
  39.       printf("I don't see %s\n",argv[1]);
  40.       exit(1);                                  }
  41.    else {
  42.       printf("Making %s O.K. for ED as file: %s\n",argv[1],argv[2]);
  43.       fp2 = fopen(argv[2],"w");           /* everything's OK, open outfile */
  44.         }
  45.  
  46.    if (argc > 3)                             /* is there a third argument? */
  47.       sscanf(argv[3],"%d", &maxlen);   /* change from character to decimal */
  48.    else
  49.       maxlen = SETLENGTH;         /* No third argument.  Set it to default */
  50.  
  51.   {
  52.       while ((c = getc(fp1)) != EOF)
  53.          if ((c == LFEED) || (c == RETURN) || (c >= SPACE && c < DELETE)) {
  54.             if (++len == maxlen) { /* if maxlen=0 this will never be true */
  55.                len = 0;        /* if true reset len (line length counter) */
  56.                putc(LFEED, fp2); }       /* force a linefeed into outfile */
  57.             if(c == LFEED || c == RETURN)/* if there is a line terminator */
  58.                len = 0;                      /* reset line length counter */
  59.             if (len > 512)                /* prevent overflow if maxlen=0 */
  60.                len = 0;
  61.       putc(c, fp2); /* pass input character to output file no matter what */
  62.                                                                           }
  63.   }
  64.  
  65. fclose(fp1);                                     /* clean up and close up */
  66. fclose(fp2);
  67. }
  68.  
  69.